package com.sgb.kjwl.view.ui.activity.self.publish;

import android.content.Context;
import android.content.Intent;
import androidx.databinding.DataBindingUtil;
import android.text.TextUtils;
import android.view.View;

import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityDevicePublishDetailBinding;
import com.sgb.kjwl.di.device.DaggerDeviceComponent;
import com.sgb.kjwl.di.device.DeviceModule;
import com.sgb.kjwl.model.entity.DeviceAttrEntity;
import com.sgb.kjwl.model.entity.DeviceDetailEntity;
import com.sgb.kjwl.viewmodel.self.publish.DevicePublishDetailModel;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.util.DialogUtil;
import com.swgk.core.util.MDateUtil;

import java.util.List;

import javax.inject.Inject;
@Deprecated
public class DevicePublishDetailActivity extends AppActivity {

    @Inject
    DevicePublishDetailModel viewModel;
    private ActivityDevicePublishDetailBinding binding;
    private DeviceDetailEntity data;

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerDeviceComponent.builder().appComponent(appComponent).deviceModule(new DeviceModule(this)).build().inject(this);
    }

    public static void start(Context context, String id) {
        Intent intent = new Intent(context, DevicePublishDetailActivity.class);
        intent.putExtra("id", id);
        context.startActivity(intent);
    }

    @Override
    protected void init() {
        String id = getIntent().getStringExtra("id");
        viewModel.getDetail(id);
        viewModel.getAttr(id);
    }


    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(this, R.layout.activity_device_publish_detail);
        binding.ivBack.setOnClickListener(this);
        binding.tvCallContact.setOnClickListener(this);
        binding.tvCallSgb.setOnClickListener(this);
    }

    public void showDetail(DeviceDetailEntity data) {
        this.data = data;
        binding.tvTitle.setText(data.getTitle());
//        binding.banner.setDelayTime(5000).setImageLoader(new GlideImageLoader()).setImages(data.getPictures()).start();
        binding.tvUpdate.setText("更新时间：" + MDateUtil.getDate(data.getUpdateTime()));
        binding.tvPrice.setText(data.getPriceUnit());
        binding.tvName.setText(TextUtils.isEmpty(data.getBrandNo()) ? "未知" : data.getBrandNo());
        binding.tvCode.setText(TextUtils.isEmpty(data.getTypeNo()) ? "未知" : data.getTypeNo());
        binding.tvLocate.setText(data.getDistrictNo() + data.getDistrictName());

        binding.tvDetail.setText(data.getDescribe());

        binding.tvTelName1.setText(data.getContacts());
        binding.tvTel1.setText(data.getContactNumberAll());
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.tv_call_contact:
                DialogUtil.showTelDialog(this, data.getContacts(), data.getContactNumberAll());
                break;
            case R.id.tv_call_sgb:
                DialogUtil.showTelDialog(this, "客服电话", "4000010051");
                break;
        }
    }

    public void showAttr(List<DeviceAttrEntity> list) {
        for (int i = 0; i < list.size(); i++) {
            switch (i) {
                case 0:
                    binding.llAttr1.setVisibility(View.VISIBLE);
                    binding.tv1.setText(list.get(i).getName());
                    binding.tvAttr1.setText(list.get(i).getAttributeVal() + list.get(i).getUnit());
                    break;
                case 1:
                    binding.llAttr2.setVisibility(View.VISIBLE);
                    binding.tv2.setText(list.get(i).getName());
                    binding.tvAttr2.setText(list.get(i).getAttributeVal() + list.get(i).getUnit());
                    break;
                case 2:
                    binding.llAttr3.setVisibility(View.VISIBLE);
                    binding.tv3.setText(list.get(i).getName());
                    binding.tvAttr3.setText(list.get(i).getAttributeVal() + list.get(i).getUnit());
                    break;
                case 3:
                    binding.llAttr4.setVisibility(View.VISIBLE);
                    binding.tv4.setText(list.get(i).getName());
                    binding.tvAttr4.setText(list.get(i).getAttributeVal() + list.get(i).getUnit());
                    break;
            }
        }
    }
}
